package main

import "fmt"

func printSlice(arr []int) {
	fmt.Printf("len = %d, capacity = %d , arr = %v\n", len(arr), cap(arr), arr)
}

// 切片
func slice() {
	fmt.Println()
	fmt.Println("=========slice========")
	fmt.Println()

	// 切片
	sliceA := []string{"a", "b", "c", "d", "e", "f"}
	sliceB := sliceA[0:1]
	sliceC := sliceA[0:]
	sliceD := sliceA[:2]
	// 初始化
	inta := make([]int, 5, 10)

	fmt.Println(inta)
	fmt.Println(sliceB)
	fmt.Println(sliceC)
	fmt.Println(sliceD)

	fmt.Println(inta)
	fmt.Println(len(inta))
	fmt.Println(cap(inta))
	inta = append(inta, 7)
	inta = append(inta, 7)
	inta = append(inta, 7)
	inta = append(inta, 7)
	inta = append(inta, 7)
	inta = append(inta, 7)
	fmt.Println(inta)
	fmt.Println(len(inta))
	fmt.Println(cap(inta))

	// 未初始化的切片是null，长度和容量都是0
	var null []int
	fmt.Println(len(null), cap(null), null)
	if null == nil {
		fmt.Println(nil)
	}

	var num1 []int
	num1 = append(num1, 0)
	printSlice(num1)

	num1 = append(num1, 1)
	printSlice(num1)

	num1 = append(num1, 2, 3, 4)
	printSlice(num1)

	num2 := make([]int, len(num1), cap(num1)*2)
	copy(num1, num2)
	printSlice(num2)

}
